package com.atguigu.srb.core.controller.admin;

import com.atguigu.common.result.R;
import com.atguigu.srb.core.pojo.dto.CommunityInfor;
import com.atguigu.srb.core.pojo.entity.ChallengeTable;
import com.atguigu.srb.core.pojo.entity.CommunityActivities;
import com.atguigu.srb.core.pojo.entity.CommunityInformation;
import com.atguigu.srb.core.pojo.entity.CooperationTable;
import com.atguigu.srb.core.service.CommunityInformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "社团信息管理")
@CrossOrigin
@RestController
@RequestMapping("/admin/core/communityInformation")
@Slf4j
public class CommunityInformationController {



    @Resource
    private CommunityInformationService communityInformationService;

    // 显示社团列表
    @ApiOperation("返回所有社团")
    @GetMapping
    public R getAllCommunities() {

        List<CommunityInfor> communityInforList = communityInformationService.CommunityList();

        return R.ok().data("community",communityInforList);

    }
    @ApiOperation("查询本社团的挑战(团员版)")
    @GetMapping("/selectchallenge/{communitynumber}")
    public R selectchallenge(
            @ApiParam(value = "社团编号")
            @PathVariable String communitynumber
    ){
        List<ChallengeTable> challengeTables=communityInformationService.getchallengtable(communitynumber);
        if(challengeTables !=null){
            return R.ok().data("list",challengeTables).message("查询成功");
        }else {
            return R.ok().message("无挑战");
        }
    }

    // 查看社团详情
    @ApiOperation("查看某个社团信息")
    @GetMapping("/{id}")
    public R getCommunityDetails(
            @ApiParam(value = "社团id",required = true)
            @PathVariable int id) {
        CommunityInformation result = communityInformationService.getById(id);


        return R.ok().data("communitydata",result);
    }

    // 收藏社团
    @ApiOperation("用户收藏社团")
    @PostMapping("/{id}/favorite")
    public R favoriteCommunity(
            @ApiParam(value = "社团信息id",required = true)
            @PathVariable int id) {
         Boolean result =  communityInformationService.redisofid(id);
         if (result){
             return  R.ok().message("收藏成功");
         }else {
             return R.error().message("收藏失败");
         }
    }

    //查看收藏列表

   //查看本社团合作（团员版）
   @ApiOperation("查询本社团的合作(团员版)")
   @GetMapping("/selectcooperation/{communitynumber}")
   public R selectcooperation(
           @ApiParam(value = "社团编号")
           @PathVariable String communitynumber
   ){
       List<CooperationTable> challengeTables=communityInformationService.getcooperation(communitynumber);
       if(challengeTables !=null){
           return R.ok().data("list",challengeTables).message("查询成功");
       }else {
           return R.ok().message("无合作");
       }
   }
   //查询社团活动
    @ApiOperation("查询所有社团活动")
    @GetMapping("/selectacticity")
    public R selectacticity(){

       List<CommunityActivities> communityActivities = communityInformationService.selectacticity();
        if(communityActivities !=null){
            return R.ok().data("list",communityActivities).message("查询成功");
        }else {
            return R.ok().message("无活动");
        }
    }

}
